package com.collabscm.pf.persistence.support;

import java.util.Map;

import com.collabscm.pf.BaseObject;
import com.collabscm.pf.persistence.WhereCondition;

/**
 * 最简单的Where条件
 * 例如：t.attr1=:attr1，将被分解为parameterName="attr1", whereClause="t.attr1=:attr1"
 *
 * @author Zeng Raoxing
 */
public class SimpleWhereCondition extends BaseObject implements WhereCondition {
	private static final long serialVersionUID = 1L;
	/**
	 * 参数名字
	 */
	private String parameterName;
	/**
	 * Where子句
	 */
	private String condition;
	/**
	 * 后续连接串
	 */
	private String continueJoinString;
	
	public SimpleWhereCondition(String parameterName, String condition, String continueJoinString) {
		this.parameterName = parameterName;
		this.condition = condition;
		this.continueJoinString = continueJoinString;
	}
	
	public String getParameterName() {
		return parameterName;
	}

	@Override
	public String getCondition() {
		return condition;
	}
	
	public void setContinueJoinString(String continueJoinString) {
		this.continueJoinString = continueJoinString;
	}

	@Override
	public String toString() {
		return "parameterName=" + parameterName + ", condition=" + condition;
	}

	@Override
	public String buildCurrentCondition(Map<String, Object> filters) {
		if(filters.containsKey(parameterName)) {
			return condition;
		}
		return null;
	}

	@Override
	public String getContinueJoinString() {
		return continueJoinString;
	}
}